package com.invokestatic.shooter;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Input.Keys;

public class Input implements InputProcessor {
	
	public static final int GENERAL = 0;
	public static final int UP = 1;
	public static final int DOWN = 2;
	public static final int LEFT = 3;
	public static final int RIGHT = 4;
	public static final int SHOOT = 5;
	public static final int SPRINT = 6;
	public static final int DEBUG = 255;
	
	public static int mouseX = 0;
	public static int mouseY = 0;
	
	
	public boolean[] buttons = new boolean[256];
	public boolean[] oldButtons = new boolean[256];

	public void set(int key, boolean down) {
		int button = -1;
		
		if(key == Keys.DPAD_UP) button = UP;
		if(key == Keys.DPAD_LEFT) button = LEFT;
		if(key == Keys.DPAD_DOWN) button = DOWN;
		if(key == Keys.DPAD_RIGHT) button = RIGHT;
		
		if(key == Keys.W) button = UP;
		if(key == Keys.A) button = LEFT;
		if(key == Keys.S) button = DOWN;
		if(key == Keys.D) button = RIGHT;
		
		if(key == Keys.SPACE) button = SHOOT;
		
		if(key == Keys.SHIFT_LEFT || key == Keys.SHIFT_RIGHT) button = SPRINT;
		
		if(key == 68) {
			button = DEBUG;
		}
		
		if(button >= 0) {
			buttons[GENERAL] = down;
			buttons[button] = down;
		} else {
			buttons[GENERAL] = down;
		}
	}
	
	public void tick () {
		for(int i = 0; i < buttons.length; i++)
			oldButtons[i] = buttons[i];
		if(Gdx.app.getType() == ApplicationType.Desktop) {
			mouseX = (int) (Gdx.input.getX()/ (float)Gdx.graphics.getWidth() * 1280);
			mouseY = (int) (Gdx.input.getY()/ (float)Gdx.graphics.getHeight() * 720);
//			System.out.println("Mouse is at : "+mouseX + ","+mouseY);
		} else if(Gdx.app.getType() == ApplicationType.Android) {
//			ApplicationType.
		}
	}
	
	
	@Override
	public boolean keyDown(int keycode) {
		set(keycode, true);
		return false;
	}

	@Override
	public boolean keyUp(int keycode) {
		set(keycode, false);
		return false;
	}

	@Override
	public boolean keyTyped(char character) {
		return false;
	}

	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		return false;
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		return false;
	}

	@Override
	public boolean touchDragged(int screenX, int screenY, int pointer) {
		return false;
	}

	@Override
	public boolean mouseMoved(int screenX, int screenY) {
		return false;
	}

	@Override
	public boolean scrolled(int amount) {
		return false;
	}

}
